<?php include_partial('common/flashes') ?>
<?php if (!$sf_request->isMethod('POST')): ?>
    <?php echo '<div id="anonymous-question-form-holder">' ?>
<?php endif; ?>
<?php $anonymousQuestionDetails = $sf_user->getQuestionDetails(); ?>
<form id="anonymous-question-form" action="<?php echo url_for('@question_anonymous') ?>" method="post">
    <?php echo $form->renderHiddenFields(true) ?>
    <div class="imperative">Enter your question here:</div>
    <?php include_partial("common/input_field", array("form" => $form, "field" => "enquiry", "show_label" => false)) ?>
    <div class="imperative">You may specify an email to be able to receive the answers!</div>
    <?php include_partial("common/input_field", array("form" => $form, "field" => "email")) ?>
    <div class="imperative">Have you a friend whom you want to receive the answers too?</div>
    <?php include_partial("common/input_field", array("form" => $form, "field" => "friend_email")) ?>
    <div class="row">
        <ul>
            <li id="ask-now-item">
                <span class="question-counter-numerator" id="anonymous-question-counter" disabled="disabled"><?php echo isset($anonymousQuestionDetails['enquiry']) ? strlen($anonymousQuestionDetails['enquiry']) : 0 ?></span>
                <span class="question-counter-denominator">/150</span>
                <button id="ask-now-button" class="blue-button-30 submit-question" type="submit">Ask now</button>             
            </li>
        </ul>
    </div>
</form>
<script type="text/javascript">
    //<![CDATA[
    $(document).ready(function(){        
        $('#anonymous_question_enquiry').focus(function() { 
            $this = $(this);
            $this.height(54);
            if($.trim($this.val()) == $this.attr('title')) {
                $this.val('');
            }            
        }).blur(function() {
            $this = $(this);
            if(!$.trim($this.val())) {
                $this.val($this.attr('title'));
                $this.height(27);
            }
        });
        
        $('#anonymous_question_enquiry').keydown(function(event) {
            $this = $(this);
            $questionCounter = $('#anonymous-question-counter');
            if($this.val().length > 150 && event.which != 8 && event.which != 46){
                return false;
            }
            else{
                newQuestionCounter = $this.val().length;
                $questionCounter.html(newQuestionCounter);
                
                healthQualityPercent = $('#health-quality-percent').html();                
                healthQualityPercent = parseFloat(parseFloat(healthQualityPercent) + 0.03333);
                
                // update the health quality value
                $('#health-quality-percent').html(healthQualityPercent);
            }
        });
        
        // make an attempt to submit this form
        $('#ask-now-button').click(function() {            
            $("#anonymous-question-form").hide();
            $("#anonymous-question-form-holder").append(loadingHtml);
            if($.trim($('#anonymous_question_enquiry').val()) == 'Ask new question...')
            {
                $('#anonymous_question_enquiry').val('');
            }
            $('#anonymous-question-form').ajaxSubmit(function(data){
                $("#anonymous-question-form-holder").html(data);        
            });
            return false;
        });
    });
    //]]>
</script>
<?php if (!$sf_request->isMethod('POST')): ?>
    <?php echo '</div>' ?>
<?php endif; ?>